//
//  UIButton+CJBadge.m
//  DatangLife
//
//  Created by 陈建 on 2018/7/12.
//  Copyright © 2018年 DatangLife. All rights reserved.
//

#import "UIButton+CJBadge.h"

@implementation UIButton (CJBadge)
- (void)showBadgeOnItemWithButtonWidth:(CGFloat)btnW withbuttonHeight:(CGFloat)btnH{
    //移除之前的小红点
    [self removeBadgeOnItem];
    //新建小红点
    UIView *badgeView = [[UIView alloc]init];
    badgeView.tag = 888;
    badgeView.layer.cornerRadius = 5;
    badgeView.backgroundColor = [UIColor redColor];
    
    //确定小红点的位置
    
    
    float percentX = 0.7;
    CGFloat x = ceilf(percentX * btnW);
    CGFloat y = 0.1 * btnH;
    badgeView.frame = CGRectMake(x, y, 10, 10);
    [self addSubview:badgeView];
    
}
- (void)hideBadgeOnItem{
    //移除小红点
    [self removeBadgeOnItem];
    
}
- (void)removeBadgeOnItem{
    //按照tag值进行移除
    for (UIView *subView in self.subviews) {
        if (subView.tag == 888) {
            [subView removeFromSuperview];
        }
        
    }
}
@end
